package AbstractTransaction

import (
	"fmt"
	"log"
	"salary_payment_case/DataBase"
	"salary_payment_case/Model"
	"strconv"
)

type ChangeEmployeeTransaction struct {
	itsEmpid int
	ChangeTransaction
}

type ChangeTransaction interface {
	Change(employee *Model.Employee)
}

func (ch *ChangeEmployeeTransaction) SetEmpid(empid int) {
	ch.itsEmpid = empid
}

func (ch *ChangeEmployeeTransaction) Execute() {
	a := DataBase.PayrollDatabase.GetEmployee(ch.itsEmpid)

	if a == nil {
		err := fmt.Errorf(DataBase.PayrollExceptionMessage.EmployeeNotExist + strconv.Itoa(transaction.itsEmpid))
		log.Println(err.Error())
		return
	}

	ch.Change(a)
}
